package com.kaigejava.demo.business.barrgelog.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.google.common.collect.Lists;
import com.kaigejava.demo.business.barrgelog.dto.BarrageLogDTO;
import com.kaigejava.demo.business.barrgelog.dto.DanMuMsgDTO;
import com.kaigejava.demo.business.barrgelog.entity.BarrageLogEntity;
import com.kaigejava.demo.business.barrgelog.mapper.BarrageLogMapper;
import com.kaigejava.demo.business.barrgelog.service.IBarrageLogService;
import com.kaigejava.demo.business.enums.TypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tech.ordinaryroad.live.chat.client.bilibili.msg.DanmuMsgMsg;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @BelongsProject: douyin-live-java
 * @BelongsPackage: com.kaigejava.demo.business.barrgelog.service.impl
 * @Author: kaigejava
 * @CreateTime: 2023-11-10  19:00
 * @Description: 弹幕记录实现类型
 * @Version: 1.0
 */
@Service
@Slf4j
public class BarrageLogServiceImpl implements IBarrageLogService {

    @Resource
    private BarrageLogMapper barrageLogMapper;

    @Override
    public Long saveInfo(BarrageLogEntity entity) {
        entity.setStatus(0);
        entity.setCreateTime(new Date());
        entity.setSendStatus(0);
        barrageLogMapper.insert(entity);
        return  entity.getId();
    }

    @Override
    public void save(DanMuMsgDTO msg, String code) {
        BarrageLogEntity entity = new BarrageLogEntity();
        entity.setUserId(msg.getUserId());
        entity.setUserName(msg.getUserName());
        entity.setContent(msg.getContent());
        entity.setStationType(code);
        entity.setCreateTime(new Date());
        entity.setStatus(0);
        entity.setSendStatus(0);
        entity.setRoomId(msg.getRoomId());
        barrageLogMapper.insert(entity);
    }

    @Override
    public List<BarrageLogEntity> selectByCode(String typeCode) {
        return barrageLogMapper.selectByCode(typeCode);
    }



    @Override
    public PageInfo<BarrageLogEntity> selectPage(Page<BarrageLogEntity> pageInfo, String typeCode) {
        PageInfo<BarrageLogEntity> pageInfos = PageMethod.startPage((int)pageInfo.getCurrent(),(int)pageInfo.getSize())
                .doSelectPageInfo(()-> barrageLogMapper.selectByCode(typeCode));

        return pageInfos;
    }
}
